<!--
 * 配置管理
 * @author luguoxiang
 * @date 2023-03-27
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
-->
<template>
  <t-form ref="form" :data="model" :colon="true">
    <t-form-item label="登录页背景图" name="loginBg">
      <div style="--lg-upload-w: 124px; --lg-upload-h: 208px">
        <lg-upload v-model="model.loginBg" value-type="url" type="img" thumb-level="m" anon-url-able />
      </div>
    </t-form-item>
  </t-form>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { LgUpload, useWaitUpload } from '@/soar';
import api from '@/api/sysConfig';

const code = 'app';
const model = ref({});
const form = ref();
const { upload } = useWaitUpload();

function load() {
  api.get(code).then((res) => {
    model.value = res ?? {};
  });
}

defineExpose({
  submit() {
    form.value.validate().then(() => {
      upload().then(() => {
        api.set(code, model.value);
      });
    });
  },
  reset() {
    return form.value.reset();
  },
});

onMounted(() => {
  load();
});
</script>
